package top.rish.utils.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.LogManager;

public class Logger {

	private static java.util.logging.Logger log = null;

	private Logger(){}

	public   void info(String msg,Object... args){
		 getLogger();
		String format = String.format(msg, args);
 		 log.log(Level.INFO,format);
	}

	public   void warn(String msg,Object... args){
		getLogger();
		String format = String.format(msg, args);
		log.log(Level.WARNING,format);
	}


	public static Logger getLogger(){
		InputStream is = null;
		try {
			if(null == log){
				//is = JavaLog.class.getResourceAsStream("/logger.properties");//也可
				is  = Logger.class.getClassLoader().getResourceAsStream("logger.properties");
				LogManager.getLogManager().readConfiguration(is);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(null != is) is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		log = java.util.logging.Logger.getLogger("LOGGER");

		return new Logger();
	}

}